HTML5 Game Devs Forum 您所在的位置:网站首页 pixi loader HTML5 Game Devs Forum

HTML5 Game Devs Forum

#HTML5 Game Devs Forum| 来源: 网络整理| 查看: 265

Quote

I put together an example of using Google Web Font which seems to work reliably.

This method, with the set interval, is called polling and its generally a fallback for when other methods do not work as its wasteful to repeatedly call a function when you don't need to. Seeing as the WebfontLoader uses callbacks you don't need to poll, just fire whatever function you like when the fonts have loaded (its been a while since I dug in to webfont loader but its entirely possible it uses polling itself to avoid errant load events, but you have no such concerns about its callbacks getting fired).

As you're loading the font in the head (which is a good idea when possible) in the 'active' callback you'd want to make sure that the setup function you want to fire exists already to deal with the case that the fonts load before your script. This way results in your setup function getting called a max of 3 times whereas polling with a 20ms gap means it'll get called roughly 50 times per second and depending on your connection you could be waiting a bit for fonts. If the fonts do indeed load before your setup function is declared then thats cool because now you'll only call it twice (once explicitly and once from the image loader).

In this example its fairly terse but ditching polling when possible is something to consider.



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有